package cn.cmkj.auction.data.http;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by cunguoyao on 2017/8/27.
 */

public class MainRecommend implements Serializable {

    private String title;
    private String type;
    private List<MainRecommendGoods> goods;

    public static class MainRecommendGoods {
        private long id;
        private String bn;
        private String name;
        private double price;
        private String image_default_id;

        public long getId() {
            return id;
        }

        public void setId(long id) {
            this.id = id;
        }

        public String getBn() {
            return bn;
        }

        public void setBn(String bn) {
            this.bn = bn;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        public String getImage_default_id() {
            return image_default_id;
        }

        public void setImage_default_id(String image_default_id) {
            this.image_default_id = image_default_id;
        }

        public static MainRecommendGoods parseJson(JSONObject jsonObject) {
            if(jsonObject == null)return null;
            MainRecommendGoods bean = new MainRecommendGoods();
            bean.setId(jsonObject.optLong("goods_id", 0));
            bean.setBn(jsonObject.optString("bn", ""));
            bean.setName(jsonObject.optString("name"));
            bean.setPrice(jsonObject.optDouble("price"));
            bean.setImage_default_id(jsonObject.optString("image_default_id"));
            return bean;
        }

        public static List<MainRecommendGoods> parseJsonArray(JSONArray jsonArray) {
            List<MainRecommendGoods> list = new ArrayList<>();
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    MainRecommendGoods bean = parseJson(jsonArray.optJSONObject(i));
                    list.add(bean);
                }
            }
            return list;
        }
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<MainRecommendGoods> getGoods() {
        return goods;
    }

    public void setGoods(List<MainRecommendGoods> goods) {
        this.goods = goods;
    }

    public static MainRecommend parseJson(JSONObject jsonObject) {
        MainRecommend bean = new MainRecommend();
        String type = jsonObject.optString("type", "");
        bean.setType(type);
        bean.setTitle(jsonObject.optString("title", ""));
        List<MainRecommendGoods> list = MainRecommendGoods.parseJsonArray(jsonObject.optJSONArray("goods"));
        if(list != null) {
            bean.setGoods(list);
        }
        return bean;
    }

    public static List<MainRecommend> parseJsonArray(JSONArray jsonArray) {
        List<MainRecommend> list = new ArrayList<>();
        if(jsonArray != null && jsonArray.length() > 0) {
            for(int i=0;i<jsonArray.length();i++) {
                MainRecommend bean = parseJson(jsonArray.optJSONObject(i));
                list.add(bean);
            }
        }
        return list;
    }
}
